using UnityEngine;

public class PlayerState : ScriptableObject, IState
{
    /*************标准组件*************/
    protected Animator animator;                                            // 动画组件
    protected PlayerStateMachine stateMachine;                              // 玩家状态机类
    
    /****动画检测*****/
    float stateStartTime;                                                   // 动画开始时间
    [SerializeField] private string stateName;                              // 动画名字
    [SerializeField,Range(0,1)] private float transitionDuration = 0.1f;    // 动画间过渡时间
    protected int stateHash;                                                // 动画状态的Hash值
    protected bool isAnimationFinished => stateDuration >= animator.GetCurrentAnimatorStateInfo(0).length;          //当前动画是否播放完毕
    protected float stateDuration => Time.time - stateStartTime;            // 动画播放的当前时间
    
    /*******组件传递*******/
    public void Initiatize(
        Animator animator,
        PlayerStateMachine stateMachine)
    {
        this.animator = animator;
        this.stateMachine = stateMachine;
    }
    private void OnEnable()
    {
        // stateHash = Animator.StringToHash(stateName);
    }
    public virtual void Enter()
    {
        stateHash = Animator.StringToHash(stateName);
        animator.CrossFade(stateHash,transitionDuration);
        stateStartTime = Time.time;
    }

    public virtual void Exit()
    {
        //
    }

    public virtual void LogicUpdate()
    {
        // 设置玩家朝向
        // animator.SetFloat("Vertical", PlayerInput.Instance.Vertical);
        // animator.transform.localScale = new Vector3(PlayerInput.Instance.Horizontal, 1, 1);
    }

    public virtual void PhysicalUpdate()
    {
        //
    }
}